#include "Map.h"
#include <stdio.h>

Map::Map()
{
	m_table = NULL;
	m_lin = 0;
	m_col = 0;
}

Map::Map(Map &map)
{
	m_lin = map.GetLines();
	m_col = map.GetColumns();
	m_table = map.GetTable();
}

Map::Map(char *fileName)
{
	unsigned int i,j;
	FILE *file = fopen(fileName,"r+t");
	if(file != NULL)
	{
		fscanf(file,"%d%d",&m_lin,&m_col);
		m_table = new int*[m_lin];
		for(i = 0 ; i < m_lin ; i++)
			m_table[i] = new int[m_col];

		for(i = 0 ; i < m_lin ; i++)
			for(j = 0 ; j < m_col ; j++)
				fscanf(file,"%d",&m_table[i][j]); // 1 noeud accessible, 0 impossible
		fclose(file);
	}
	else
	{
		m_table = NULL;
		m_lin = 0;
		m_col = 0;
	}
}

Map::~Map()
{
	unsigned int i;
	for(i = 0 ; i < m_lin ; i++)
	{
		if(m_table != NULL && m_table[i] != NULL)
		{
			delete []m_table[i];
			m_table[i] = NULL;
		}
	}
	if(m_table != NULL)
	{
		delete []m_table;
		m_table = NULL;
	}
}